package demo.module_login.net;

import org.json.JSONObject;

import demo.module_login.m.data.UserInfo;
import io.reactivex.Observable;
import module.common.net.Response;
import module.common.net.TokenInterceptor;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;

/**
 * @author Created by qiang.hou on 2018/12/4.
 * @version 1.0
 */
public interface ILoginApi {
    /**
     * 登录接口
     *
     * @param userName 用户名/手机号
     * @param password 密码
     * @return Observable
     */
    @FormUrlEncoded
    @Headers(TokenInterceptor.HEADER_NO_NEED_TOKEN)
    @POST("api/v3/login")
    Observable<Response<UserInfo>> loginByPassword(@Field("username") String userName,
                                                   @Field("password") String password);

    /**
     * 验证码登录接口
     *
     * @param phoneNum         手机号
     * @param verificationCode 验证码
     * @return Observable
     */
    @FormUrlEncoded
    @Headers(TokenInterceptor.HEADER_NO_NEED_TOKEN)
    @POST("api/v3/login/phonecode")
    Observable<Response<UserInfo>> loginByCode(@Field("phoneNum") String phoneNum,
                                               @Field("verificationCode") String verificationCode);

    /**
     * 获取验证码
     *
     * @param phoneNumber 手机号
     * @return Observable
     */
    @Headers(TokenInterceptor.HEADER_NO_NEED_TOKEN)
    @GET("api/v3/login/verificationcode/{phoneNum}")
    Observable<Response<Object>> verificationCode(@Path("phoneNum") String phoneNumber);

    /**
     * 检查手机号是否注册
     *
     * @param phoneNumber 手机号
     * @return Observable
     */
    @Headers(TokenInterceptor.HEADER_NO_NEED_TOKEN)
    @GET("api/v3/login/phoneregister/{phoneNum}")
    Observable<Response<JSONObject>> checkPhoneIfRegistered(@Path("phoneNum") String phoneNumber);

    /**
     * 设置密码
     *
     * @return Observable
     */
    @FormUrlEncoded
    @Headers(TokenInterceptor.HEADER_NEED_TOKEN)
    @POST("api/v3/login/password")
    Observable<Response<Object>> setPassword(@Field("phoneNum") String phoneNum,
                                               @Field("password") String password,
                                               @Field("confirmPwd") String confirmPwd);
}
